<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
use Illuminate\Support\Facades\DB;

class CreateAdminAttachmentsTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        if (!Schema::hasTable('admin_attachments')) {
            Schema::create('admin_attachments', function (Blueprint $table) {
                $table->id();
                $table->integer('uid')->default(0)->comment('上传用户, 0 为公共图片');
                $table->string('type', 32)->comment('附件类型, image图片/music音乐/video视频/file文档/office办公文档/compress压缩/other其它');
                $table->string('filename')->comment('文件名');
                $table->string('path')->comment('文件路径, 不带有域名, 为 Storage 访问路径');
                $table->integer('size')->default(0)->comment('文件大小');
                $table->string('mimetype')->comment('文件 MimeType');
                $table->string('suffix', 32)->comment('文件后缀名');
                $table->string('dir', 32)->nullable()->comment('管理文件夹');
                $table->json('meta')->nullable()->comment('文件其它数据');
                $table->timestamps();
            });
            DB::statement("ALTER TABLE `admin_attachments` comment '附件表'");
        }
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists('admin_attachments');
    }
}
